home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / POV-Ray 3.0.2 / src / MacSource / AppPrefs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-23  |  34.0 KB  |  1,127 lines  |  [TEXT/CWIE]

  1. /*==============================================================================
  2. Project:    POV-Ray
  3.  
  4. Version:    3
  5.  
  6. File:    AppPrefs.c
  7.  
  8. Description: Application preferences dialog and handlers
  9. ------------------------------------------------------------------------------
  10. Author:
  11.     Eduard [esp] Schwan
  12. ------------------------------------------------------------------------------
  13.     from Persistence of Vision(tm) Ray Tracer
  14.     Copyright 1996 Persistence of Vision Team
  15. ------------------------------------------------------------------------------
  16.     NOTICE: This source code file is provided so that users may experiment
  17.     with enhancements to POV-Ray and to port the software to platforms other 
  18.     than those supported by the POV-Ray Team.  There are strict rules under
  19.     which you are permitted to use this file.  The rules are in the file
  20.     named POVLEGAL.DOC which should be distributed with this file. If 
  21.     POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  22.     Team Coordinator by leaving a message in CompuServe's Graphics Developer's
  23.     Forum.  The latest version of POV-Ray may be found there as well.
  24.  
  25.     This program is based on the popular DKB raytracer version 2.12.
  26.     DKBTrace was originally written by David K. Buck.
  27.     DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  28. ------------------------------------------------------------------------------
  29. Change History:
  30.     941230    [esp]    Created
  31.     960210    [esp]    3.0b5, added KeepGoingOnErrors
  32.     960621    [esp]    3.0b7, Changed Prefs file Creator type back to POV-Ray <bug-Steve Luce>
  33. ==============================================================================*/
  34.  
  35. #define APPPREFS_C
  36.  
  37. /*==== my header =====*/
  38. #include "AppPrefs.h"
  39. #include "ScreenUtils.h"
  40. #include "DialogUtils.h"        // DisplayModalDialog
  41.  
  42.  
  43. // Application prefs file type
  44. #define    kPrefsFileType            'PREF'
  45.  
  46.  
  47. /*==== Macintosh-specific headers ====*/
  48. #include <errors.h>            /* dupFNErr, etc */
  49. #include <files.h>            /* fsspec */
  50. #include <folders.h>        /* konsystemdisk */
  51. #include <TextUtils.h>        /* GetIndString */
  52. #include <Resources.h>
  53. #include <Sound.h>            // soundListRsrc
  54. #include <gestalt.h>        // gestaltFindFolderAttr
  55. #include <Processes.h>    // GetProcessInformation
  56. #include <PPCToolBox.h>    // PPCBrowser
  57.  
  58. #include "volspaths.h" // pathnamefromdirid
  59. #include "stdfolder.h" // SF_PromptForFolder
  60.  
  61.  
  62.  
  63. // ---------------------------------------------------------------------
  64.  
  65. #define kDlogID_AppPrefs    2001
  66.  
  67. //
  68. // POV-Ray Prefs Dialog items
  69. //
  70. #define    kPU_AppThrottle                4
  71. #define    kBT_ChooseSearchPath        5
  72. #define    kST_SearchPath                6
  73. #define    kCB_AutoTemplates            7
  74. #define    kCB_ShowSplashScreen        8
  75. #define    kCB_UseAppDefaultPrefs        9
  76. #define    kPU_SoundsPopup                10
  77. #define    kCB_AutoSaveImage            11
  78. #define    kPU_AllDoneNotify            12
  79. #define    kCB_ShutDownWhenDone        13
  80. #define    kCB_AddCustomIcons            14
  81. #define    kCB_KeepGoingOnErrors        15
  82.  
  83.  
  84.  
  85. /*==== globals ====*/
  86. app_prefs_hdl_t        gAppPrefs_h = NULL;                // App prefs from prefs file
  87. file_prefs_hdl_t    gDefltFilePrefs_h = NULL;        // default file prefs from prefs file
  88. Boolean                gUseAppDefaultPrefs = false;    // True if overriding file prefs
  89. Boolean                gShutDownWhenDone = false;        // True if shutting down computer
  90.  
  91. /*==== locals ====*/
  92. static    short                gAppPrefsRefNum = kRsrcFileClosed;
  93. static     app_prefs_rec_t        gOrigPrefs;
  94. static    FSSpec                gTempFSS;
  95.  
  96.  
  97. // ---------------------------------------------------------------------
  98. // Application Prefs accessors
  99.  
  100. void APSet_TimeSlice(short newValue)
  101.     {
  102.     (**gAppPrefs_h).appThrottle    = newValue;
  103.     } // APSet_TimeSlice
  104.  
  105. short APGet_TimeSlice(void)
  106.     {
  107.     return (**gAppPrefs_h).appThrottle;
  108.     } // APSet_TimeSlice
  109.  
  110.  
  111. // ---------------------------------------------------------------------
  112. void APSet_AutoTemplates(Boolean newValue)
  113.     {
  114.     (**gAppPrefs_h).autoLoadTemplates    = newValue;
  115.     } // APSet_AutoTemplates
  116.  
  117. Boolean APGet_AutoTemplates(void)
  118.     {
  119.     return (**gAppPrefs_h).autoLoadTemplates;
  120.     } // APGet_AutoTemplates
  121.  
  122.  
  123. // ---------------------------------------------------------------------
  124. void APSet_AllDoneSoundID(short newValue)
  125.     {
  126.     (**gAppPrefs_h).allDoneSoundID    = newValue;
  127.     } // APSet_AllDoneSoundID
  128.  
  129. short APGet_AllDoneSoundID(void)
  130.     {
  131.     return (**gAppPrefs_h).allDoneSoundID;
  132.     } // APGet_AllDoneSoundID
  133.  
  134.  
  135. // ---------------------------------------------------------------------
  136. void APSet_AutoSaveImage(Boolean newValue)
  137.     {
  138.     (**gAppPrefs_h).autoSavePict    = newValue;
  139.     } // APSet_AutoSaveImage
  140.  
  141. Boolean APGet_AutoSaveImage(void)
  142.     {
  143.     return (**gAppPrefs_h).autoSavePict;
  144.     } // APGet_AutoSaveImage
  145.  
  146.  
  147. // ---------------------------------------------------------------------
  148. void APSet_AllDoneNotify(short newValue)
  149.     {
  150.     (**gAppPrefs_h).allDoneNotify    = newValue;
  151.     } // APSet_AllDoneNotify
  152.  
  153. short APGet_AllDoneNotify(void)
  154.     {
  155.     return (**gAppPrefs_h).allDoneNotify;
  156.     } // APGet_AllDoneNotify
  157.  
  158.  
  159. // ---------------------------------------------------------------------
  160. void APSet_UseAppDefaultPrefs(Boolean newValue)
  161.     {
  162.     (**gAppPrefs_h).useAppDefaultPrefs    = newValue;
  163.     // now actually switch which prefs to use
  164.     if (newValue)
  165.         gPrefs2Use_h = gDefltFilePrefs_h; // default file prefs
  166.     else
  167.         gPrefs2Use_h = gFilePrefs_h; // regular file prefs
  168.     } // APSet_UseAppDefaultPrefs
  169.  
  170. Boolean APGet_UseAppDefaultPrefs(void)
  171.     {
  172.     return (**gAppPrefs_h).useAppDefaultPrefs;
  173.     } // APGet_UseAppDefaultPrefs
  174.  
  175.  
  176. // ---------------------------------------------------------------------
  177. void APSet_UseTempMem(Boolean newValue)
  178.     {
  179.     (**gAppPrefs_h).useTempMem    = newValue;
  180.     } // APSet_UseTempMem
  181.  
  182. Boolean APGet_UseTempMem(void)
  183.     {
  184.     return (**gAppPrefs_h).useTempMem;
  185.     } // APGet_UseTempMem
  186.  
  187.  
  188. // ---------------------------------------------------------------------
  189. void APSet_ShowSplashScreen(Boolean newValue)
  190.     {
  191.     (**gAppPrefs_h).showSplashScreen = newValue;
  192.     } // APSet_ShowSplashScreen
  193.  
  194. Boolean APGet_ShowSplashScreen(void)
  195.     {
  196.     return (**gAppPrefs_h).showSplashScreen;
  197.     } // APGet_ShowSplashScreen
  198.  
  199. // ---------------------------------------------------------------------
  200. void APSet_AddCustomIcons(Boolean newValue)
  201.     {
  202.     (**gAppPrefs_h).addCustomIcons = newValue;
  203.     } // APSet_AddCustomIcons
  204.  
  205. Boolean APGet_AddCustomIcons(void)
  206.     {
  207.     return (**gAppPrefs_h).addCustomIcons;
  208.     } // APGet_AddCustomIcons
  209.  
  210.  
  211. // ---------------------------------------------------------------------
  212. void APSet_ShutDownWhenDone(Boolean newValue)
  213.     {
  214.     gShutDownWhenDone = newValue;
  215.     } // APSet_ShutDownWhenDone
  216.  
  217. Boolean APGet_ShutDownWhenDone(void)
  218.     {
  219.     return gShutDownWhenDone;
  220.     } // APGet_ShutDownWhenDone
  221.  
  222.  
  223. // ---------------------------------------------------------------------
  224. void APSet_KeepGoingOnErrors(Boolean newValue)
  225.     {
  226.     (**gAppPrefs_h).keepGoingOnErrors = newValue;
  227.     } // APSet_KeepGoingOnErrors
  228.  
  229. Boolean APGet_KeepGoingOnErrors(void)
  230.     {
  231.     return (**gAppPrefs_h).keepGoingOnErrors;
  232.     } // APGet_KeepGoingOnErrors
  233.  
  234.  
  235. // ---------------------------------------------------------------------
  236. void APSet_IncludePaths(FSSpecPtr newValue)
  237.     {
  238.     (**gAppPrefs_h).includeDirFSSpec    = *newValue;
  239.     } // APSet_IncludePaths
  240.  
  241. FSSpecPtr APGet_IncludePaths(void)
  242.     {
  243.     return &(**gAppPrefs_h).includeDirFSSpec;
  244.     } // APGet_IncludePaths
  245.  
  246.  
  247. // ---------------------------------------------------------------------
  248. void APSet_AppPrefsDlgPos(Rect * r)
  249.     {
  250.     (**gAppPrefs_h).appPrefsDlgPos = *r;
  251.     } // APSet_AppPrefsDlgPos
  252.  
  253. void APGet_AppPrefsDlgPos(Rect * r)
  254.     {
  255.     *r = (**gAppPrefs_h).appPrefsDlgPos;
  256.     } // APGet_AppPrefsDlgPos
  257.  
  258.  
  259. // ---------------------------------------------------------------------
  260. void APSet_FilePrefsDlgPos(Rect * r)
  261.     {
  262.     (**gAppPrefs_h).filePrefsDlgPos = *r;
  263.     } // APSet_FilePrefsDlgPos
  264.  
  265. void APGet_FilePrefsDlgPos(Rect * r)
  266.     {
  267.     *r = (**gAppPrefs_h).filePrefsDlgPos;
  268.     } // APGet_FilePrefsDlgPos
  269.  
  270.  
  271. // ---------------------------------------------------------------------
  272. // Create a default include FSSPec (first launch of POV-Ray, no prefs file)
  273. static void GetDefaultIncludePath(FSSpec * tempFSSpecPtr)
  274. {
  275.     OSErr                anError = noErr;
  276.     ProcessSerialNumber    myPSN;
  277.     ProcessInfoRec        myPSRec;
  278.     CInfoPBRec            myPBlock;
  279.     Str255                relPath;
  280.  
  281. //printf("-d-GetDefaultIncludePath()\n"); // <debug>
  282.  
  283.     // What is our Process ID?
  284.     anError = GetCurrentProcess(&myPSN);
  285.  
  286. //printf("-d-  GetCurrentProcess err=%d\n",anError); // <debug>
  287.  
  288.     // Use that Process ID to get info on this app, specifically its directory
  289.     if (!anError)
  290.         {
  291.         // prepare to read process info
  292.         myPSRec.processInfoLength = sizeof(ProcessInfoRec);
  293.         myPSRec.processName = NULL;
  294.         myPSRec.processAppSpec = tempFSSpecPtr;
  295.         // read app's FSSpec
  296.         anError = GetProcessInformation(&myPSN, &myPSRec);
  297.         }
  298.  
  299. //printf("-d-  GetProcessInformation pvref=%d pdirid=%d err=%d\n", myPSRec.processAppSpec->vRefNum, myPSRec.processAppSpec->parID, anError); // <debug>
  300.  
  301.     // find the relative path name to the :INCLUDE: folder, get from resource.
  302.     // (This is set to look up one level, then down into "INCLUDE")
  303.     if (!anError)
  304.         {
  305.         GetIndString(relPath, kSTRI_FileNames, kSTRIi_INCLUDE_Def);
  306.         anError = ResError();
  307.         }
  308.  
  309.     // now use app directory + relative path to find true dirID.
  310.     if (!anError)
  311.         {
  312.         // set up to find dirID of the :INCLUDE: directory
  313.         myPBlock.dirInfo.ioCompletion    = NULL;
  314.         myPBlock.dirInfo.ioNamePtr        = relPath;
  315.         myPBlock.dirInfo.ioVRefNum        = tempFSSpecPtr->vRefNum;
  316.         myPBlock.dirInfo.ioFDirIndex    = 0;
  317.         myPBlock.dirInfo.ioDrDirID        = tempFSSpecPtr->parID;
  318.         // look it up
  319.         anError = PBGetCatInfoSync(&myPBlock);
  320. //printf("-d-  PBGetCatInfoSync dirID=%ld err=%d\n", tempFSSpecPtr->parID, anError); // <debug>
  321.         // if found, stick new dirID into fsspec
  322.         if (!anError)
  323.             tempFSSpecPtr->parID = myPBlock.dirInfo.ioDrDirID;
  324.         }
  325.  
  326.     // OK, the vrefnum and DirID are correct, now fill in the name field
  327.     // with the name of the volume (vrefnum).  This is just a safe way to
  328.     // store volumes (by name) that POV-Ray uses.
  329.     if (!anError)
  330.         {
  331.         // stick the volume name into the FSSpec name field
  332.         anError = VRef2VolName(tempFSSpecPtr->vRefNum, tempFSSpecPtr->name);
  333. //printf("-d-  VRef2VolName(%d,'%s') err=%d\n", tempFSSpecPtr->vRefNum, tempFSSpecPtr->name, anError); // <debug>
  334.         }
  335. }
  336.  
  337. // ---------------------------------------------------------------------
  338. // Find and open the Application Prefs file
  339. OSErr AppPrefs_Open(void)
  340. {
  341.     long        theResponse;        /* For call to Gestalt */
  342.     OSErr        anError = noErr;
  343.     Boolean        createdResFile=false;
  344.     Handle        resH;
  345.     FSSpec        prefsFileFS;
  346.  
  347.     // fill in the Prefs file name from resource
  348.     GetIndString(prefsFileFS.name, kSTRI_FileNames, kSTRIi_Prefs);
  349.     anError = ResError();
  350.  
  351.     // Find the preferences folder
  352.     if (anError == noErr)
  353.         anError = Gestalt(gestaltFindFolderAttr, &theResponse);
  354.  
  355.     if ((anError == noErr) && (theResponse & (1<<gestaltFindFolderPresent) ) )
  356.       anError = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
  357.          &prefsFileFS.vRefNum, &prefsFileFS.parID);
  358.  
  359.     // Try to create the prefs file.
  360.     if (!anError)
  361.         {
  362.         FSpCreateResFile(&prefsFileFS, kAppSignature/*kAppXtraSignature*/, kPrefsFileType, (ScriptCode)NULL);
  363.            anError = ResError();
  364.         }
  365.  
  366.     // file's already created?  Not an error, but remember for later down
  367.     if (anError == noErr)
  368.         createdResFile=true;
  369.     else if (anError == dupFNErr)
  370.         anError = noErr;
  371.  
  372.     if (anError == noErr)
  373.     {
  374.         gAppPrefsRefNum = FSpOpenResFile(&prefsFileFS, fsRdWrPerm);
  375.            if (gAppPrefsRefNum == kRsrcFileClosed)
  376.                anError = -1;    // preset in case there is NO ResError
  377.            if (ResError())
  378.                anError = ResError();
  379.        }
  380.  
  381.     if (createdResFile && (anError==noErr))
  382.     {
  383.         // get Finder "Don't Open" error string from app and add it to prefs file
  384.         resH = GetResource('STR ', +16397);    // get from application
  385.         if (resH)
  386.             {
  387.                 DetachResource(resH); // this copy no longer belongs to app
  388.                 AddResource(resH, 'STR ', -16397, "\pSo don't do that!"); // add to file
  389.             }
  390.         // get vers 2 from app and add it to prefs file
  391.         resH = GetResource('vers', 2);    // get from application
  392.         if (resH)
  393.             {
  394.                 DetachResource(resH); // this copy no longer belongs to app
  395.                 AddResource(resH, 'vers', 2, "\pOwner App"); // add to file
  396.             }
  397.     }
  398.  
  399.     return anError;
  400. } // AppPrefs_Open
  401.  
  402.  
  403.  
  404. // ---------------------------------------------------------------------
  405. // Close the Application Prefs file
  406. void AppPrefs_Close(void)
  407. {
  408.     CloseResFile (gAppPrefsRefNum);
  409.     gAppPrefsRefNum = kRsrcFileClosed;
  410. } // AppPrefs_Close
  411.  
  412.  
  413.  
  414. // ---------------------------------------------------------------------
  415. // Write the prefs resource back to the app prefs file
  416. void AppPrefs_Write(void)
  417. {
  418.     OSErr                theResError = noErr;
  419.     short                AppRefNum;
  420.     file_prefs_hdl_t    tmpFileHandle = NULL;
  421.     app_prefs_hdl_t        tmpAppHandle = NULL;
  422.  
  423.     AppRefNum = CurResFile();
  424.     theResError = AppPrefs_Open();
  425.  
  426.     if (theResError != noErr)
  427.     {
  428. // DEBUG <>
  429. (void)DisplayModalDialog(kdlog_GenericFatalErr, ok, 0,
  430. "AppPrefs_Write: Couldn't open prefs file", theResError, ewcDoCentering, eMainDevice);
  431.     }
  432.     else
  433.     {
  434.         UseResFile(gAppPrefsRefNum);
  435.  
  436.         // as long as there are old prefs resources, delete them..
  437.         // note that I'm getting by index, so as to get any rsrc id #s..
  438.         do {
  439.             // App prefs
  440.             tmpAppHandle = (app_prefs_hdl_t)Get1IndResource(kAppPrefsRsrc, 1);
  441.             if (tmpAppHandle != NULL)
  442.             {
  443.                 RemoveResource((Handle)tmpAppHandle);
  444.                 UpdateResFile(gAppPrefsRefNum);
  445.                 DisposeHandle((Handle)tmpAppHandle);
  446.             }
  447.         } while (tmpAppHandle != NULL);
  448.         do {
  449.             // Default File prefs
  450.             tmpFileHandle = (file_prefs_hdl_t)Get1IndResource(kFilePrefsRsrc, 1);
  451.             if (tmpFileHandle != NULL)
  452.             {
  453.                 RemoveResource((Handle)tmpFileHandle);
  454.                 UpdateResFile(gAppPrefsRefNum);
  455.                 DisposeHandle((Handle)tmpFileHandle);
  456.             }
  457.         } while (tmpFileHandle != NULL);
  458.         
  459.         /* Create a new app prefs resource to add */
  460.         tmpAppHandle = (app_prefs_hdl_t)NewHandle(sizeof(app_prefs_rec_t));
  461.     
  462.         /* Fill it up and add it to file */
  463.         if (tmpAppHandle != NULL)
  464.         {
  465.             **tmpAppHandle = **gAppPrefs_h;
  466.             AddResource((Handle)tmpAppHandle, kAppPrefsRsrc, kAppPrefs_rsrcID, "\pPOV-Ray App Prefs");
  467.             theResError = ResError();
  468.             if (!theResError)
  469.                 {
  470.                 WriteResource((Handle)tmpAppHandle);
  471.                 theResError = ResError();
  472.                 }
  473.         }
  474.     
  475.         /* Create a new default file prefs resource to add */
  476.         if (theResError == noErr)
  477.             tmpFileHandle = (file_prefs_hdl_t)NewHandle(sizeof(file_prefs_rec_t));
  478.     
  479.         /* Fill it up and add it to file */
  480.         if ((tmpFileHandle != NULL) && (theResError == noErr))
  481.         {
  482.             **tmpFileHandle = **gDefltFilePrefs_h;
  483.             AddResource((Handle)tmpFileHandle, kFilePrefsRsrc, kFilePrefs_rsrcID, "\pPOV-Ray Default File Prefs");
  484.             theResError = ResError();
  485.             if (!theResError)
  486.                 {
  487.                 WriteResource((Handle)tmpFileHandle);
  488.                 theResError = ResError();
  489.                 }
  490.         }
  491.         UseResFile(AppRefNum);
  492.     
  493.         if ((theResError) || (tmpAppHandle == NULL) || (tmpFileHandle == NULL))
  494.         {
  495.             // error updating prefs file
  496.             DisplayModalDialog(144, ok, 0, NULL, theResError, ewcDoCentering, eMainDevice);
  497.             gAppPrefs_h = NULL;
  498.             exit_handler();
  499.         }
  500.  
  501.         // All done, clean up shop
  502.         AppPrefs_Close();
  503.  
  504.     } // if !error
  505.     UseResFile(AppRefNum);
  506. } // AppPrefs_Write
  507.  
  508.  
  509.  
  510. // ---------------------------------------------------------------------
  511. // Open the App prefs file & get the prefs out of the file.  If the file
  512. // is out of date or doesn't exist, create a new one and fill it with defaults.
  513. void AppPrefs_Read(void)
  514. {
  515.     OSErr                theResError = noErr;
  516.     short                AppRefNum;
  517.     file_prefs_hdl_t    tmpFileHandle = NULL;
  518.     app_prefs_hdl_t        tmpAppHandle = NULL;
  519.  
  520.     AppRefNum = CurResFile();
  521.     theResError = AppPrefs_Open();
  522.  
  523.     // Get saved prefs for POV_Ray prefs dialog from the app prefs file
  524.     if (theResError != noErr)
  525.     {
  526. // DEBUG <>
  527. (void)DisplayModalDialog(kdlog_GenericFatalErr, ok, 0,
  528. "AppPrefs_Read: Couldn't open prefs file", theResError, ewcDoCentering, eMainDevice);
  529.     }
  530.     else
  531.     {
  532.         UseResFile(gAppPrefsRefNum);
  533.         theResError = ResError();
  534.  
  535.         // read app prefs
  536.         if (theResError == noErr)
  537.         {
  538.             tmpAppHandle = (app_prefs_hdl_t) Get1Resource(kAppPrefsRsrc, kAppPrefs_rsrcID);
  539.             theResError = ResError();
  540.             if (theResError != noErr)
  541.                 tmpAppHandle = NULL;
  542.         }
  543.     
  544.         // read default file prefs
  545.         if (theResError == noErr)
  546.         {
  547.             tmpFileHandle = (file_prefs_hdl_t) Get1Resource(kFilePrefsRsrc, kFilePrefs_rsrcID);
  548.             theResError = ResError();
  549.             if (theResError != noErr)
  550.                 tmpFileHandle = NULL;
  551.         }
  552.     
  553.         if (theResError != noErr)
  554.         {
  555.             // error creating prefs file
  556.             (void)DisplayModalDialog(145, ok, 0, NULL, theResError, ewcDoCentering, eMainDevice);
  557.             exit_handler();
  558.         }
  559.     
  560.         // did we get the App prefs?
  561.         if (tmpAppHandle != NULL)
  562.         {
  563.             // Is it the wrong version? Delete it if so..
  564.             if ((**tmpAppHandle).prefsVersion != kAppPrefs_Vers)
  565.             {
  566.                 RemoveResource((Handle)tmpAppHandle);
  567.                 UpdateResFile(gAppPrefsRefNum);
  568.                 DisposeHandle((Handle)tmpAppHandle);
  569.                 tmpAppHandle = NULL; // flag code below to add new
  570.             }
  571.         }
  572.     
  573.         // did we get the Default File prefs?
  574.         if (tmpFileHandle != NULL)
  575.         {
  576.             // Is it the wrong version or did we fail to get App prefs? Delete file prefs if so..
  577.             if ( ((**tmpFileHandle).prefsVersion != kFilePrefs_Vers)
  578.             || (tmpAppHandle == NULL) )
  579.             {
  580.                 RemoveResource((Handle)tmpFileHandle);
  581.                 UpdateResFile(gAppPrefsRefNum);
  582.                 DisposeHandle((Handle)tmpFileHandle);
  583.                 tmpFileHandle = NULL; // flag code below to add new
  584.             }
  585.         }
  586.     
  587.         // Still got App Prefs?  Use it!
  588.         if (tmpAppHandle != NULL)
  589.         {
  590.             // copy contents from rsrc to our memory buffer
  591.             **gAppPrefs_h = **tmpAppHandle;
  592.  
  593.             // ---------------------------------------------------------------
  594.             // NOTE: Certain App Prefs are dangerous to remember between runs...
  595.             // for example "Shut down when done".  Always reset these to safer values.
  596.             // ---------------------------------------------------------------
  597.             APSet_UseAppDefaultPrefs(FALSE);
  598.             APSet_ShutDownWhenDone(FALSE);
  599.  
  600.             // make sure our dialogs are on screen
  601.             ForceRectOnScreen(&(**gAppPrefs_h).appPrefsDlgPos);
  602.             ForceRectOnScreen(&(**gAppPrefs_h).filePrefsDlgPos);
  603.             // all done with the resource, scuttle it
  604.             ReleaseResource((Handle)tmpAppHandle);
  605.         }
  606.  
  607.         // Still got File Prefs?  Use it!
  608.         if (tmpFileHandle != NULL)
  609.         {
  610.             // copy contents from rsrc to our memory buffer
  611.             **gDefltFilePrefs_h = **tmpFileHandle;
  612.  
  613.             // make sure our windows are visible on THIS MACHINE'S screens
  614.             ForceRectOnScreen(&(**gDefltFilePrefs_h).srcWind_pos);
  615.             ForceRectOnScreen(&(**gDefltFilePrefs_h).statWind_pos);
  616.             ForceRectOnScreen(&(**gDefltFilePrefs_h).imageWind_pos);
  617.             ReleaseResource((Handle)tmpFileHandle);
  618.         }
  619.     
  620.         // return to app rsrc for dialogs
  621.         UseResFile(AppRefNum);
  622.     
  623.         // All done, clean up shop
  624.         AppPrefs_Close();
  625.  
  626.         // fill & add new ones if we couldn't read or use the old ones
  627.         if ((tmpAppHandle == NULL) || (tmpFileHandle == NULL))
  628.         {
  629.             // Beep at user to let them know of update
  630.             SysBeep(4);
  631.  
  632.             //
  633.             // --- set global app record to defaults
  634.             //
  635.  
  636.             if (tmpAppHandle == NULL)
  637.             {
  638.                 Rect        tempRect;
  639.                 FSSpec        tempFSSpec;
  640.  
  641.                 // set default app prefs values
  642.                 (**gAppPrefs_h).prefsVersion    = kAppPrefs_Vers;
  643.  
  644.                 APSet_TimeSlice(eThrottle_Default);
  645.                 APSet_UseAppDefaultPrefs(FALSE);
  646.                 APSet_AutoTemplates(TRUE);
  647.                 APSet_AllDoneSoundID(1003); // just to make people want to change it! :-)
  648.                 APSet_AllDoneNotify(eDone_Beep);
  649.                 APSet_AutoSaveImage(TRUE);
  650.                 APSet_UseAppDefaultPrefs(FALSE);
  651.                 APSet_UseTempMem(FALSE);
  652.                 APSet_ShowSplashScreen(TRUE);
  653.                 APSet_ShutDownWhenDone(FALSE);
  654.                 APSet_AddCustomIcons(TRUE);
  655.                 APSet_KeepGoingOnErrors(FALSE);
  656.  
  657.                 // create default INCLUDE path starting from current application directory
  658.                 GetDefaultIncludePath(&tempFSSpec);
  659.                 APSet_IncludePaths(&tempFSSpec);
  660.                 // dialog positions
  661.                 SetRect(&tempRect,    // left, top, right, bottom
  662.                                 qd.screenBits.bounds.left + 30,
  663.                                 qd.screenBits.bounds.top + GetMBarHeight()+50,
  664.                                 qd.screenBits.bounds.left + 30+200,
  665.                                 qd.screenBits.bounds.top + GetMBarHeight()+50+200);
  666.                 APSet_AppPrefsDlgPos(&tempRect);
  667.                 APSet_FilePrefsDlgPos(&tempRect);
  668.             } // if (tmpAppHandle == NULL)
  669.  
  670.             //
  671.             // --- set global default file record to defaults
  672.             //
  673.  
  674.             if (tmpFileHandle == NULL)
  675.             {
  676. //                FillDefaultFilePrefs(*gDefltFilePrefs_h);
  677.                 (**gDefltFilePrefs_h).prefsVersion = kFilePrefs_Vers;
  678.  
  679.                 // SOURCE window
  680.                 SetRect(&(**gDefltFilePrefs_h).srcWind_pos,    // left, top, right, bottom
  681.                                 qd.screenBits.bounds.left + 2,
  682.                                 qd.screenBits.bounds.top + GetMBarHeight()+40,
  683.                                 min(qd.screenBits.bounds.left + 480, qd.screenBits.bounds.right - 40),
  684.                                 400);
  685.  
  686.                 // STATUS window
  687.                 SetRect(&(**gDefltFilePrefs_h).statWind_pos,    // left, top, right, bottom
  688.                                 qd.screenBits.bounds.left + 3,
  689.                                 qd.screenBits.bounds.bottom - 260,
  690.                                 min(qd.screenBits.bounds.left + 480, qd.screenBits.bounds.right - 40),
  691.                                 qd.screenBits.bounds.bottom - 20);
  692.     
  693.                 // IMAGE window
  694.                 SetRect(&(**gDefltFilePrefs_h).imageWind_pos,    // left, top, right, bottom
  695.                                 qd.screenBits.bounds.left + 1,
  696.                                 qd.screenBits.bounds.top + GetMBarHeight()+20,
  697.                                 0, 0); // not used
  698.     
  699.                 SetPt(&(**gDefltFilePrefs_h).LastPrefsDlgPos, 0, 0);
  700.     
  701.                 (**gDefltFilePrefs_h).imageWidth        = 100; // x
  702.                 (**gDefltFilePrefs_h).imageHeight        = 100; // y
  703.                 (**gDefltFilePrefs_h).imageUpperLeft.h    = 0;
  704.                 (**gDefltFilePrefs_h).imageUpperLeft.v    = 0;
  705.  
  706.                 SetRect(&(**gDefltFilePrefs_h).selectionArea, 1, 1,
  707.                         (**gDefltFilePrefs_h).imageWidth,
  708.                         (**gDefltFilePrefs_h).imageHeight);
  709.  
  710.                 (**gDefltFilePrefs_h).pictFileCreator    = 'ttxt';
  711.                 (**gDefltFilePrefs_h).targaFileCreator    = '8BIM';
  712.  
  713.                 // Create Ini file
  714.                 (**gDefltFilePrefs_h).doCreateINI        = false;
  715.  
  716.                 (**gDefltFilePrefs_h).renderQuality        = 9;
  717.                 (**gDefltFilePrefs_h).radQuality        = 0;
  718.                 (**gDefltFilePrefs_h).custom_palette    = palette_median;
  719.                 (**gDefltFilePrefs_h).imageMagFactor    = viewmn_normal;
  720.  
  721.                 (**gDefltFilePrefs_h).outfileType = eOutfNone;
  722.                 (**gDefltFilePrefs_h).outfileBuffSize    = 0;
  723.                 (**gDefltFilePrefs_h).continueTarga        = false;
  724.                 (**gDefltFilePrefs_h).bitsPerColor        = 8;
  725.                 (**gDefltFilePrefs_h).doAlphaChannel    = false;
  726.                 (**gDefltFilePrefs_h).doDither            = true;
  727.                 (**gDefltFilePrefs_h).doPictCompression    = false;
  728.         
  729.                 (**gDefltFilePrefs_h).doBoundSlabs        = true;
  730.                 (**gDefltFilePrefs_h).boundSlabThreshold = 5;
  731.  
  732.                 (**gDefltFilePrefs_h).progress            = eProgMac;
  733.                 (**gDefltFilePrefs_h).languageVersion    = eMaxLangVersion;
  734.  
  735.                 (**gDefltFilePrefs_h).previewStart        = 3; // 0=off 1,2,3,4
  736.                 (**gDefltFilePrefs_h).previewEnd        = 1;
  737.  
  738.                 (**gDefltFilePrefs_h).doAntialias        = false;
  739.                 (**gDefltFilePrefs_h).antialiasMethod    = 1; // 1 or 2
  740.                 (**gDefltFilePrefs_h).antialiasThreshold = 0.30;
  741.                 (**gDefltFilePrefs_h).antialiasDepth    = 3;
  742.                 (**gDefltFilePrefs_h).antiJitterScale    = 0.0;
  743.  
  744.                 (**gDefltFilePrefs_h).doHistogram        = false;
  745.                 (**gDefltFilePrefs_h).histogramType        = 1;
  746.                 (**gDefltFilePrefs_h).histogramXSize    = 0;
  747.                 (**gDefltFilePrefs_h).histogramYSize    = 0;
  748.  
  749.                 (**gDefltFilePrefs_h).doFieldRender        = false;
  750.                 (**gDefltFilePrefs_h).doOddField        = true;
  751.  
  752.                 (**gDefltFilePrefs_h).doSplitUnions        = true;
  753.                 (**gDefltFilePrefs_h).removeBounds        = true;
  754.                 (**gDefltFilePrefs_h).doVistaBuffer        = true;
  755.                 (**gDefltFilePrefs_h).doLightBuffer        = true;
  756.                 (**gDefltFilePrefs_h).doVistaDraw        = false;
  757.  
  758.                 // CLOCK - animation    
  759.                 (**gDefltFilePrefs_h).doAnimation        = false;
  760.                 (**gDefltFilePrefs_h).animRec.frameVal0    = 1;
  761.                 (**gDefltFilePrefs_h).animRec.frameValN    = 20; // some medium # of frames
  762.                 (**gDefltFilePrefs_h).animRec.frameValS    = (**gDefltFilePrefs_h).animRec.frameVal0;
  763.                 (**gDefltFilePrefs_h).animRec.frameValE    = (**gDefltFilePrefs_h).animRec.frameValN;
  764.                 (**gDefltFilePrefs_h).animRec.clockVal0    = 0.0;
  765.                 (**gDefltFilePrefs_h).animRec.clockValN    = 1.0;
  766.  
  767.                 // Initial defaults for SC compression dialog    
  768.                 if (gtheSCComponent)
  769.                 {
  770.                     (void)SCGetInfo(gtheSCComponent, scSpatialSettingsType, &(**gDefltFilePrefs_h).sc_DialogParams);
  771.                 }
  772.             } // if (tmpFileHandle == NULL)
  773.  
  774.             // Save our settings
  775.             AppPrefs_Write();
  776.     
  777.         } // didn't get it, create new
  778.     
  779.         // make sure file prefs is initialized too
  780.         **gFilePrefs_h = **gDefltFilePrefs_h; // initialize this to defaults
  781.     
  782.         // set up our current prefs to be those of the file.
  783.         // This can be changed with the App Prefs dialog
  784.         gPrefs2Use_h = gFilePrefs_h;
  785.  
  786.     }
  787.     UseResFile(AppRefNum);
  788. } // AppPrefs_Read
  789.  
  790.  
  791.  
  792. // ---------------------------------------------------------------------
  793. static Boolean PromptForSearchPath(FSSpecPtr theDirFSSpecPtr)
  794. {
  795.     Point                sfWhere;
  796.     StandardFileReply    theReply;
  797.  
  798.     // preset Std file to start out at current FSSpec folder
  799.     SF_SetSFCurrent(theDirFSSpecPtr);
  800.  
  801.     // prompt for Include files
  802.     GetBestDialogPos(&sfWhere, (WindowPtr)gp2wWindow);
  803.     SF_PromptForFolder(sfWhere, "\pFind the POV-Ray INCLUDE folder", &theReply);
  804.  
  805.     if (!theReply.sfGood)
  806.         return false;
  807.     else
  808.     {
  809.         *theDirFSSpecPtr = theReply.sfFile;
  810.  
  811. printf("-d-PromptForSearchPath() pvref=%d pdirid=%d\n",
  812. theReply.sfFile.vRefNum, theReply.sfFile.parID); // <debug>
  813.  
  814.         return true;
  815.     }
  816. } // PromptForSearchPath
  817.  
  818.  
  819. // ---------------------------------------------------------------------
  820. // When we finally have time to add ful AppleScript and connect to remote POV-Rays
  821. static void DoConnectPrompt(void)
  822.     {
  823.     OSErr            anError;
  824.     LocationNameRec    pLocNameRec;
  825.     PortInfoRec        pPortInfoRec;
  826.  
  827.     anError = PPCBrowser(
  828.             "\pChoose a POV-Ray Server",
  829.             "\pPOV-Servers",
  830.             false,            // no defaults
  831.             &pLocNameRec,
  832.             &pPortInfoRec,
  833.             NULL,
  834.             NULL
  835.             );
  836.     } // DoConnectPrompt
  837.  
  838.  
  839. // ---------------------------------------------------------------------
  840. // Get the menu handle of a popup menu
  841. static MenuRef GetPopupMenuHandle(DialogPtr dlgWindPtr, short popupDitlID)
  842.     {
  843.     ControlHandle    popupControlH = NULL;
  844.     MenuRef            theMenuRef = NULL;
  845.  
  846.     // get the popup menu control, then get menu handle from it
  847.     popupControlH = (ControlHandle)GrabDItemHandle(dlgWindPtr, popupDitlID);
  848.     // popup menu handle inside struct pointed to by contrlData handle! (NIM:Essentials:5-28,5-77)
  849.     if (popupControlH)
  850.         theMenuRef = (MenuRef) (**(Handle**)(**popupControlH).contrlData);
  851.     return theMenuRef;
  852.     }
  853.  
  854. // ---------------------------------------------------------------------
  855. // Initialize the sound popup menu with list of sounds
  856. static void InitSoundsPopup(DialogPtr dlgWindPtr)
  857.     {
  858.     int            k;
  859.     short        menuItemFound;
  860.     short        theSoundRsrcID = 0;
  861.     MenuRef        soundsMenuRef = NULL;
  862.     OSType        theSoundRsrcType;
  863.     Handle        theSoundRsrcH = NULL;
  864.     Str255        userSoundName;
  865.     Str255        menuSoundName;
  866.  
  867.     // get the popup menu
  868.     soundsMenuRef = GetPopupMenuHandle(dlgWindPtr, kPU_SoundsPopup);
  869.     // add all the sounds in the app and system to this menu
  870.     if (soundsMenuRef)
  871.         {
  872.         // (all the sounds are added to the menu automatically by the popup CNTL)
  873.         // now search the menu for the previously chosen sound,
  874.         // so we can set that as the current menu item
  875.         theSoundRsrcH = GetResource(soundListRsrc, APGet_AllDoneSoundID());
  876.         // use the sound resource handle found to get its name
  877.         userSoundName[0]=0; // reset string in case it is not found
  878.         if (theSoundRsrcH)
  879.             GetResInfo(theSoundRsrcH, &theSoundRsrcID, &theSoundRsrcType, userSoundName);
  880.         // now loop through menu items comparing names until we find a match
  881.         menuItemFound = 1; // assume first item until we really find one
  882.         for (k=1; k<CountMenuItems(soundsMenuRef); k++)
  883.             {
  884.             // get this menu item's name
  885.             GetMenuItemText(soundsMenuRef, k, menuSoundName);
  886.             if (0 == CompareString(userSoundName, menuSoundName, NULL))
  887.                 {
  888.                 // found it!
  889.                 menuItemFound = k;
  890.                 break;
  891.                 }
  892.             }
  893.         // now menuItemFound holds the item to set the menu to,
  894.         // set current value of popup to this item
  895.         SetDialogItemValue(dlgWindPtr, kPU_SoundsPopup, menuItemFound);
  896.         }
  897.     }
  898.  
  899. // ---------------------------------------------------------------------
  900. // convert current item selected in popup menu into a sound resource ID
  901. static short GetAllDoneSoundID(DialogPtr dlgWindPtr)
  902.     {
  903.     short        itemIndex;
  904.     short        theSoundRsrcID = 0;
  905.     OSType        theSoundRsrcType;
  906.     Handle        theSoundRsrcH = NULL;
  907.     MenuRef        soundsMenuRef = NULL;
  908.     Str255        theSoundName;
  909.  
  910.     // get the currently selected item number of popup menu
  911.     itemIndex = GetDialogItemValue(dlgWindPtr, kPU_SoundsPopup);
  912.     // get the popup menu itself
  913.     soundsMenuRef = GetPopupMenuHandle(dlgWindPtr, kPU_SoundsPopup);
  914.     // now get the item text for that item, this is the sound resource name
  915.     theSoundName[0]=0; // reset string in case not found
  916.     if (soundsMenuRef)
  917.         GetMenuItemText(soundsMenuRef, itemIndex, theSoundName);
  918.     // Now search for the resource by its name
  919.     theSoundRsrcH = GetNamedResource(soundListRsrc, theSoundName);
  920.     // finally, use the sound resource handle found to get its resource ID!
  921.     if (theSoundRsrcH)
  922.         GetResInfo(theSoundRsrcH, &theSoundRsrcID, &theSoundRsrcType, theSoundName);
  923.     // return the resource ID to the caller
  924.     return theSoundRsrcID;
  925.     }
  926.  
  927.  
  928. // ---------------------------------------------------------------------
  929. // Prompt the user to change the Application Preferences
  930. static void AppPrefs_HandleEvents(EventRecord * theEventPtr)
  931.     {
  932.     short        itemHit;
  933.     Boolean        gotItem;
  934.     WindowPtr    myDialog;
  935.     Rect        dRect;
  936.     Str255        thePath;
  937.  
  938.     gotItem = false;
  939.     myDialog = GetCurrMModalDialog();
  940.  
  941.     // handle activate events
  942.     if (theEventPtr->what == activateEvt)
  943.         {
  944.         // enable or disable our main buttons on activate/deactivate
  945.         HiliteControl(GrabDItemHandle(myDialog, ok), (theEventPtr->modifiers & 1)?0:255);
  946.         HiliteControl(GrabDItemHandle(myDialog, cancel), (theEventPtr->modifiers & 1)?0:255);
  947.         }
  948.  
  949.     // Handle CR/ESC ourselves
  950.     if (theEventPtr->what == keyDown)
  951.         {
  952.         char    theKey = theEventPtr->message & charCodeMask;
  953.         if ((theKey == 13) || (theKey == 3)) // CR or ENTER
  954.             {
  955.             itemHit = ok;
  956.             gotItem = true;
  957.             FlashDItem(myDialog, itemHit);
  958.             }
  959.         if ((theKey == 27) ||        // escape key
  960.             ((theKey == '.') && (theEventPtr->modifiers & cmdKey))) // <cmd>-period
  961.             {
  962.             itemHit = cancel;
  963.             gotItem = true;
  964.             FlashDItem(myDialog, itemHit);
  965.             }
  966.  
  967.         }
  968.  
  969.     // look for other events
  970.     if (!gotItem)
  971.         gotItem = DialogSelect(theEventPtr, &myDialog, &itemHit);
  972.  
  973.     if (gotItem)
  974.         {
  975.         switch (itemHit)
  976.             {
  977.             case kBT_ChooseSearchPath:
  978.                 // Call up Standard File to let user find the path
  979.                 if (PromptForSearchPath(&gTempFSS))
  980.                     {
  981.                     // find this folder name's dirID
  982.                     gTempFSS.parID = SF_GetFSSubDirID(&gTempFSS);
  983.                     // convert it to full pathname for display
  984.                     PathNameFromDirID(gTempFSS.parID, gTempFSS.vRefNum, (char*)thePath);
  985.                     c2pstr((char*)thePath);
  986.                     SetDialogItemText((Handle)GrabDItemHandle(myDialog, kST_SearchPath), thePath);
  987.                     // save volume name in the NAME field, for permanent retrieval
  988.                     VRef2VolName(gTempFSS.vRefNum, gTempFSS.name);
  989.                     }
  990.                 break;
  991.  
  992.             case kCB_AutoTemplates:
  993.             case kCB_AutoSaveImage:
  994.             case kCB_UseAppDefaultPrefs:
  995.             case kCB_ShowSplashScreen:
  996.             case kCB_ShutDownWhenDone:
  997.             case kCB_AddCustomIcons:
  998.             case kCB_KeepGoingOnErrors:
  999.                 SetDialogItemValue(myDialog, itemHit, !GetDialogItemValue(myDialog, itemHit));
  1000.                 break;
  1001.  
  1002. // not yet...
  1003. //            case kBT_ChooseRenderer:
  1004. //                // Call up PPCBrowser
  1005. //                DoConnectPrompt();
  1006. //                break;
  1007.  
  1008.             case ok:
  1009.                 APSet_TimeSlice(GetDialogItemValue(myDialog, kPU_AppThrottle));
  1010.                 APSet_AutoTemplates(GetDialogItemValue(myDialog, kCB_AutoTemplates));
  1011.                 APSet_UseAppDefaultPrefs(GetDialogItemValue(myDialog, kCB_UseAppDefaultPrefs));
  1012.                 APSet_AllDoneSoundID(GetAllDoneSoundID(myDialog));
  1013.                 APSet_AllDoneNotify(GetDialogItemValue(myDialog, kPU_AllDoneNotify));
  1014.                 APSet_AutoSaveImage(GetDialogItemValue(myDialog, kCB_AutoSaveImage));
  1015.                 APSet_ShowSplashScreen(GetDialogItemValue(myDialog, kCB_ShowSplashScreen));
  1016.                 APSet_ShutDownWhenDone(GetDialogItemValue(myDialog, kCB_ShutDownWhenDone));
  1017.                 APSet_AddCustomIcons(GetDialogItemValue(myDialog, kCB_AddCustomIcons));
  1018.                 APSet_KeepGoingOnErrors(GetDialogItemValue(myDialog, kCB_KeepGoingOnErrors));
  1019.  
  1020.                 APSet_IncludePaths(&gTempFSS);
  1021.                 GetGlobalWindowRect(myDialog, &dRect); // ScreenUtils.c
  1022.                 APSet_AppPrefsDlgPos(&dRect);
  1023.  
  1024.                 // save prefs in file
  1025.                 AppPrefs_Write();
  1026.     
  1027.                 CloseMModalDialog();
  1028.                 EnableMenus(); // re-enable menus
  1029.                 break;
  1030.  
  1031.             case cancel:
  1032.                 **gAppPrefs_h = gOrigPrefs; // restore original values
  1033.                 CloseMModalDialog();
  1034.                 EnableMenus(); // re-enable menus
  1035.                 break;
  1036.             } // switch
  1037.         } // if
  1038.     } // AppPrefs_HandleEvents
  1039.  
  1040.  
  1041. // ---------------------------------------------------------------------
  1042. // Prompt the user to change the Application Preferences
  1043. void AppPrefs_Prompt_Init(void)
  1044.     {
  1045.     Rect            aRect;
  1046.     DialogPtr        myDialog;
  1047.     Str255            thePath;
  1048.  
  1049.     // retrieve dialog from resource
  1050.     myDialog = GetMModalDialog(kDlogID_AppPrefs);
  1051.     if (!myDialog)
  1052.         {
  1053.         SysBeep(4);
  1054.         return;
  1055.         }
  1056.  
  1057.     // set this as current dialog and event handler
  1058.     SetCurrMModalDialog(myDialog, &AppPrefs_HandleEvents);
  1059.  
  1060.     // remember temporary prefs record until user clicks OK!
  1061.     gOrigPrefs = **gAppPrefs_h;
  1062.  
  1063.     // Init the App throttle popup
  1064.     SetDialogItemValue(myDialog, kPU_AppThrottle, APGet_TimeSlice());
  1065.  
  1066.     // Init the Auto-load Templates
  1067.     SetDialogItemValue(myDialog, kCB_AutoTemplates, APGet_AutoTemplates());
  1068.  
  1069.     // Init All done Notify popup
  1070.     SetDialogItemValue(myDialog, kPU_AllDoneNotify, APGet_AllDoneNotify());
  1071.  
  1072.     // Init the done sound popup
  1073.     InitSoundsPopup(myDialog);
  1074.  
  1075.     // Init the Autosave checkbox
  1076.     SetDialogItemValue(myDialog, kCB_AutoSaveImage, APGet_AutoSaveImage());
  1077.  
  1078.     // Init the Show Splash Screen checkbox
  1079.     SetDialogItemValue(myDialog, kCB_ShowSplashScreen, APGet_ShowSplashScreen());
  1080.  
  1081.     // Init the Shut down checkbox
  1082.     SetDialogItemValue(myDialog, kCB_ShutDownWhenDone, APGet_ShutDownWhenDone());
  1083.  
  1084.     // Init the custom icon checkbox
  1085.     SetDialogItemValue(myDialog, kCB_AddCustomIcons, APGet_AddCustomIcons()&&gHasQuickTime);
  1086.     // disable it if no QuickTime present
  1087.     HiliteControl(GrabDItemHandle(myDialog, kCB_AddCustomIcons),
  1088.             gHasQuickTime?kControlNoPart:kControlInactivePart);
  1089.  
  1090.     // Init the keep going checkbox
  1091.     SetDialogItemValue(myDialog, kCB_KeepGoingOnErrors, APGet_KeepGoingOnErrors());
  1092.  
  1093.  
  1094.     // Init the default settings
  1095.     SetDialogItemValue(myDialog, kCB_UseAppDefaultPrefs, APGet_UseAppDefaultPrefs());    
  1096.     
  1097.     // convert volume name to vref for making full path
  1098.     gTempFSS = *(APGet_IncludePaths());
  1099.     VolName2VRef(gTempFSS.name, &gTempFSS.vRefNum);
  1100.  
  1101.     // make full path
  1102.     PathNameFromDirID(gTempFSS.parID, gTempFSS.vRefNum, (char*)thePath);
  1103.     c2pstr((char*)thePath);
  1104.     // stuff path into display field
  1105.     SetDialogItemText((Handle)GrabDItemHandle(myDialog, kST_SearchPath), thePath);
  1106.     TruncStaticTextItem(myDialog, kST_SearchPath);    // shorten it
  1107.  
  1108.     APGet_AppPrefsDlgPos(&aRect);
  1109.     if ((aRect.left==0) && (aRect.top==0))
  1110.         PositionWindow(myDialog, ewcDoCentering, eSameAsPassedWindow, (WindowPtr)gp2wWindow);
  1111.     else
  1112.         {
  1113.         // make sure our windows are visible on THIS MACHINE'S screens
  1114.         ForceRectOnScreen(&aRect);
  1115.         MoveWindow(myDialog, aRect.left, aRect.top, true);
  1116.         }
  1117.  
  1118.     // set the standard action for OK/cancel buttons
  1119.     InstallUserDrawProc(myDialog, kDefaultOutlineItem, &OutlineButtonDrawProc);
  1120.  
  1121.     // show it
  1122.     ShowMModalDialog();
  1123.  
  1124.     } // AppPrefs_Prompt_Init
  1125.  
  1126.  
  1127.